package com.food.springcloud.controller;

import com.ofood.springcloud.domain.Food;
import com.ofood.springcloud.domain.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
@Slf4j
public class FoodController {
    //private static final String FOOD_PROVIDER_URL="http://localhost:8001";
    private static final String SERVICE_NAME="http://ofood-food-consul-provider";
    @Resource
    private RestTemplate restTemplate;

    @PostMapping("/consul/consumer/food/create")
    public Result create(@RequestBody Food food){
        return restTemplate.postForObject(SERVICE_NAME+"/consul/food/create",food,Result.class);
    }

    @GetMapping("/consul/consumer/food/get/{foodId}")
    public Result getFoodById(@PathVariable("foodId") long foodId){
        return restTemplate.getForObject(SERVICE_NAME+"/consul/food/get/"+foodId,Result.class);
    }
}
